from .base_champion import Champion
from typing import Dict, List, Optional
import random


class ShadowAssassin(Champion):
    def __init__(self):
        super().__init__(
            name="Shadow Assassin",
            health=70,
            attack=45,
            defense=5,
            speed=30,
            mana=100
        )
    
    def get_abilities(self) -> List[str]:
        return ["Shadow Strike", "Stealth", "Poison Blade", "Shadow Clone"]
    
    def use_ability(self, ability_name: str, target: Optional[Champion] = None) -> Dict:
        if not self._is_alive:
            return {"success": False, "message": "Cannot use ability - champion is dead"}
        
        if self._is_silenced:
            return {"success": False, "message": f"{self.name} is silenced and cannot use abilities"}
        
        if ability_name == "Shadow Strike":
            return self._shadow_strike(target)
        elif ability_name == "Stealth":
            return self._stealth()
        elif ability_name == "Poison Blade":
            return self._poison_blade(target)
        elif ability_name == "Shadow Clone":
            return self._shadow_clone()
        else:
            return {"success": False, "message": f"Unknown ability: {ability_name}"}
    
    def _shadow_strike(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(30):
            return {"success": False, "message": "Not enough mana"}

        crit_chance = 0.4
        if random.random() < crit_chance:
            damage = int(self.attack * 2.5)  
            actual_damage = target.take_damage(damage, "physical")
            return {
                "success": True,
                "damage": actual_damage,
                "message": f"{self.name} performs a critical Shadow Strike on {target.name} for {actual_damage} damage!"
            }
        else:
            damage = int(self.attack * 1.5)
            actual_damage = target.take_damage(damage, "physical")
            return {
                "success": True,
                "damage": actual_damage,
                "message": f"{self.name} strikes {target.name} from the shadows for {actual_damage} damage!"
            }
    
    def _stealth(self) -> Dict:
        if not self.consume_mana(25):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "stealth",
            "evasion_boost": 50,
            "attack_boost": 10,
            "duration": 3
        })
        
        return {
            "success": True,
            "message": f"{self.name} enters Stealth mode! +50% evasion, +10 attack for 3 turns!"
        }
    
    def _poison_blade(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(20):
            return {"success": False, "message": "Not enough mana"}
        
        damage = int(self.attack * 1.2)
        actual_damage = target.take_damage(damage, "physical")
        
        target._debuffs.append({
            "type": "poison",
            "damage_per_turn": 8,
            "duration": 4
        })
        
        return {
            "success": True,
            "damage": actual_damage,
            "message": f"{self.name} strikes {target.name} with a Poison Blade for {actual_damage} damage! (Poisoned)"
        }
    
    def _shadow_clone(self) -> Dict:
        if not self.consume_mana(40):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "shadow_clone",
            "clone_count": 2,
            "duration": 4
        })
        
        return {
            "success": True,
            "message": f"{self.name} creates 2 Shadow Clones for 4 turns!"
        }
    
    def get_champion_type(self) -> str:
        return "Assassin"


class WindNinja(Champion):
    def __init__(self):
        super().__init__(
            name="Wind Ninja",
            health=85,
            attack=35,
            defense=8,
            speed=35,
            mana=110
        )
    
    def get_abilities(self) -> List[str]:
        return ["Wind Slash", "Gust", "Wind Step", "Tornado"]
    
    def use_ability(self, ability_name: str, target: Optional[Champion] = None) -> Dict:
        if not self._is_alive:
            return {"success": False, "message": "Cannot use ability - champion is dead"}
        
        if self._is_silenced:
            return {"success": False, "message": f"{self.name} is silenced and cannot use abilities"}
        
        if ability_name == "Wind Slash":
            return self._wind_slash(target)
        elif ability_name == "Gust":
            return self._gust()
        elif ability_name == "Wind Step":
            return self._wind_step()
        elif ability_name == "Tornado":
            return self._tornado()
        else:
            return {"success": False, "message": f"Unknown ability: {ability_name}"}
    
    def _wind_slash(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(25):
            return {"success": False, "message": "Not enough mana"}
        
        damage = int(self.attack * 1.3)
        actual_damage = target.take_damage(damage, "physical")
        
        return {
            "success": True,
            "damage": actual_damage,
            "message": f"{self.name} performs a Wind Slash on {target.name} for {actual_damage} damage!"
        }
    
    def _gust(self) -> Dict:
        if not self.consume_mana(20):
            return {"success": False, "message": "Not enough mana"}
        
        return {
            "success": True,
            "message": f"{self.name} creates a Gust! (Area effect - pushes back all enemies)"
        }
    
    def _wind_step(self) -> Dict:
        if not self.consume_mana(15):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "wind_step",
            "speed_boost": 15,
            "evasion_boost": 30,
            "duration": 3
        })
        
        return {
            "success": True,
            "message": f"{self.name} activates Wind Step! +15 speed, +30% evasion for 3 turns!"
        }
    
    def _tornado(self) -> Dict:
        if not self.consume_mana(45):
            return {"success": False, "message": "Not enough mana"}
        
        return {
            "success": True,
            "message": f"{self.name} creates a Tornado! (Area effect - damages and disorients all enemies)"
        }
    
    def get_champion_type(self) -> str:
        return "Assassin"


class PoisonDart(Champion):
    def __init__(self):
        super().__init__(
            name="Poison Dart",
            health=75,
            attack=40,
            defense=6,
            speed=28,
            mana=95
        )
    
    def get_abilities(self) -> List[str]:
        return ["Poison Dart", "Toxic Cloud", "Venom Strike", "Poison Mastery"]
    
    def use_ability(self, ability_name: str, target: Optional[Champion] = None) -> Dict:
        if not self._is_alive:
            return {"success": False, "message": "Cannot use ability - champion is dead"}
        
        if self._is_silenced:
            return {"success": False, "message": f"{self.name} is silenced and cannot use abilities"}
        
        if ability_name == "Poison Dart":
            return self._poison_dart(target)
        elif ability_name == "Toxic Cloud":
            return self._toxic_cloud()
        elif ability_name == "Venom Strike":
            return self._venom_strike(target)
        elif ability_name == "Poison Mastery":
            return self._poison_mastery()
        else:
            return {"success": False, "message": f"Unknown ability: {ability_name}"}
    
    def _poison_dart(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(15):
            return {"success": False, "message": "Not enough mana"}
        
        damage = int(self.attack * 1.1)
        actual_damage = target.take_damage(damage, "physical")
        
        target._debuffs.append({
            "type": "poison",
            "damage_per_turn": 6,
            "duration": 3
        })
        
        return {
            "success": True,
            "damage": actual_damage,
            "message": f"{self.name} throws a Poison Dart at {target.name} for {actual_damage} damage! (Poisoned)"
        }
    
    def _toxic_cloud(self) -> Dict:
        if not self.consume_mana(35):
            return {"success": False, "message": "Not enough mana"}
        
        return {
            "success": True,
            "message": f"{self.name} creates a Toxic Cloud! (Area effect - poisons all enemies)"
        }
    
    def _venom_strike(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(30):
            return {"success": False, "message": "Not enough mana"}
        
        damage = int(self.attack * 1.6)
        actual_damage = target.take_damage(damage, "physical")
        
        target._debuffs.append({
            "type": "venom",
            "damage_per_turn": 12,
            "duration": 5
        })
        
        return {
            "success": True,
            "damage": actual_damage,
            "message": f"{self.name} performs a Venom Strike on {target.name} for {actual_damage} damage! (Strong poison applied)"
        }
    
    def _poison_mastery(self) -> Dict:
        if not self.consume_mana(25):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "poison_mastery",
            "poison_damage_boost": 50,
            "duration": 5
        })
        
        return {
            "success": True,
            "message": f"{self.name} activates Poison Mastery! +50% poison damage for 5 turns!"
        }
    
    def get_champion_type(self) -> str:
        return "Assassin"

